package cn.xueden.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**功能描述：静态资源配置
 * @author:梁志杰
 * @date:2025/6/8
 * @description:cn.xueden.config
 * @version:1.0
 */
@Configuration
public class ResourceConfig implements WebMvcConfigurer {
    /**
     * 图片存放路径
     */
    @Value("${online-edu.storage.file-path}")
    private String filePath;

    /**
     * 静态资源文件路径映射
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 本地文件路径
        String pathUrl = "file:"+filePath.replace("\\","/");
        // 映射路径
        registry.addResourceHandler("/api/localFile/**").addResourceLocations(pathUrl).setCachePeriod(0);
    }
}
